<template>
  <el-dialog
    :title="titleMap[mode]"
    v-model="visible"
    :width="960"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :rules="rules"
      :disabled="mode == 'show'"
      ref="dialogForm"
      label-width="100px"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="编号">
            <el-input
              v-model="entityObj.Code"
              disabled
              placeholder="自动生成"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称" prop="Name">
            <el-input
              v-model="entityObj.Name"
              placeholder="请输入名称"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="类型" prop="TypeCode">
            <el-select v-model="entityObj.TypeCode" style="width: 100%">
              <el-option label="---请选择型---" value="" />
              <el-option label="直营店" value="01" />
              <el-option label="加盟店" value="02" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="操作系统" prop="OperSys">
            <el-select v-model="entityObj.OperSys" style="width: 100%">
              <el-option label="---请选操作系统---" value="" />
              <el-option label="Window" value="Window" />
              <el-option label="CentOS" value="CentOS" />
              <el-option label="Ubuntn" value="Ubuntn" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="数据库类型" prop="DBType">
            <el-select v-model="entityObj.DBType" style="width: 100%">
              <el-option label="---请选数据库类型---" value="" />
              <el-option label="SqlServer" value="SqlServer" />
              <el-option label="Mysql" value="Mysql" />
              <el-option label="Oracle" value="Oracle" />
              <el-option label="PostgreSql" value="PostgreSql"
            /></el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="版本号" prop="Version">
            <el-input
              v-model="entityObj.Version"
              placeholder="请输入版本号"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="服务器" prop="ServerStr">
            <el-input
              v-model="entityObj.ServerStr"
              placeholder="请输入服务器"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="数据库" prop="DataBaseStr">
            <el-input
              v-model="entityObj.DataBaseStr"
              placeholder="请输入数据库"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="账户" prop="UidStr">
            <el-input
              v-model="entityObj.UidStr"
              placeholder="请输入账户"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="密码" prop="PwdStr">
            <el-input
              v-model="entityObj.PwdStr"
              placeholder="请输入密码"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="OpenId" prop="NodifyOpenId">
        <el-input
          v-model="entityObj.NodifyOpenId"
          clearable
          type="textarea"
        ></el-input>
      </el-form-item>
      <el-form-item label="向日葵" prop="SunFlowerStr">
        <el-input
          v-model="entityObj.SunFlowerStr"
          clearable
          type="textarea"
        ></el-input>
      </el-form-item>
      <el-form-item label="硬件信息" prop="HardWare">
        <el-input
          v-model="entityObj.HardWare"
          clearable
          type="textarea"
        ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="Remark">
        <el-input
          v-model="entityObj.Remark"
          clearable
          type="textarea"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button
        v-if="mode != 'show'"
        type="primary"
        :loading="isSaveing"
        @click="submit()"
        >保 存</el-button
      >
    </template>
  </el-dialog>
</template>
  
  <script>
import publicjs from "@/api/model/publicjs";
export default {
  emits: ["success", "closed"],
  data() {
    return {
      mode: "add",
      titleMap: {
        add: "新增",
        edit: "编辑",
        show: "查看",
      },
      visible: false,
      isSaveing: false,
      //表单数据
      entityObj: {
        Code: "",
        Name: "",
        TypeCode: "",
        OperSys: "",
        DBType: "",
        Version: "",
        ServerStr: "",
        DataBaseStr: "",
        UidStr: "",
        PwdStr: "",
        NodifyOpenId: "",
        SunFlowerStr: "",
        HardWare: "",
        Remark: "",
      },
      //验证规则
      rules: {
        name: [{ required: true, message: "请输入名称", min: 3, max: 5 }],
        label: [{ required: true, message: "请输入部门名称" }],
      },
      //所需数据选项
      groups: [],
      groupsProps: {
        value: "id",
        emitPath: false,
        checkStrictly: true,
      },
    };
  },
  mounted() {
    this.getGroup();
  },
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },
    //加载树数据
    async getGroup() {
      var res = await this.$API.system.dept.list.get();
      this.groups = res.data;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.demo.post.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
        }
      });
    },
    //表单注入数据
    async setData(data) {
      // this.form.id = data.id;
      // this.form.label = data.label;
      // this.form.status = data.status;
      // this.form.sort = data.sort;
      // this.form.parentId = data.parentId;
      // this.form.remark = data.remark;

      //可以和上面一样单个注入，也可以像下面一样直接合并进去
      //Object.assign(this.form, data)
      //alert('aaa')
      // eslint-disable-next-line no-debugger
      ////debugger
      var head = new publicjs.head();
      publicjs.initHead(head, "getobj");
      var ed = new publicjs.entitydata(head);
      var eo = new publicjs.entityobj();
      eo.AttrList = {
        Name: "Purview",
        UseDistinct: false,
        OrgCode: "",
        UseBackUp: false,
        UseGroup: false,
      };
      eo.ValueList = {
        Code: "Code",
        Name: "Name",
        TypeCode: "TypeCode",
        OperSys: "OperSys",
        DBType: "DBType",
        Version: "Version",
        ServerStr: "ServerStr",
        DataBaseStr: "DataBaseStr",
        UidStr: "UidStr",
        PwdStr: "PwdStr",
        NodifyOpenId: "NodifyOpenId",
        SunFlowerStr: "SunFlowerStr",
        HardWare: "HardWare",
        Remark: "Remark",
      };
      eo.QueryList = { Code: data.Code };
      ed.Data.Content.ObjectList.Object.push(eo);
      try {
        var returnValueStr = await this.$API.auth.objProcess.post(ed);
        alert(returnValueStr);
        // eslint-disable-next-line no-debugger
        //debugger;
        var returnValue = JSON.parse(returnValueStr);
        if (returnValue) {
          // eslint-disable-next-line no-debugger
          //debugger;
          this.entityObj.Code =
            returnValue.Result.Content.ObjectList.Object.SetList.Code;
          this.entityObj.Name =
            returnValue.Result.Content.ObjectList.Object.SetList.Name;
          this.entityObj.TypeCode =
            returnValue.Result.Content.ObjectList.Object.SetList.TypeCode;
          this.entityObj.OperSys =
            returnValue.Result.Content.ObjectList.Object.SetList.OperSys;
          this.entityObj.DBType =
            returnValue.Result.Content.ObjectList.Object.SetList.DBType;
          this.entityObj.Version =
            returnValue.Result.Content.ObjectList.Object.SetList.Version;
          this.entityObj.ServerStr =
            returnValue.Result.Content.ObjectList.Object.SetList.ServerStr;
          this.entityObj.DataBaseStr =
            returnValue.Result.Content.ObjectList.Object.SetList.DataBaseStr;
          this.entityObj.UidStr =
            returnValue.Result.Content.ObjectList.Object.SetList.UidStr;
          this.entityObj.PwdStr =
            returnValue.Result.Content.ObjectList.Object.SetList.PwdStr;
          this.entityObj.NodifyOpenId =
            returnValue.Result.Content.ObjectList.Object.SetList.NodifyOpenId;
          this.entityObj.SunFlowerStr =
            returnValue.Result.Content.ObjectList.Object.SetList.SunFlowerStr;
          this.entityObj.HardWare =
            returnValue.Result.Content.ObjectList.Object.SetList.HardWare;
          this.entityObj.Remark =
            returnValue.Result.Content.ObjectList.Object.SetList.Remark;
        }
        //this.summary = response.summary || {};
        this.loading = false;
        //this.$refs.scTable.setScrollTop(0);
        //this.$emit('dataChange', res, this.tableData)
      } catch (error) {
        this.loading = false;
        //this.emptyText = error.statusText;
        return false;
      }
    },
  },
};
</script>
  
  <style>
</style>
  